﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    class UsersServiceDAL
    {
        public class Usersservice
        {
            public static object CONN { get; private set; }

            /// <summary>
                    /// 判断用户名和密码
                    /// </summary>
                    /// <param name="txtName"></param>
                    /// <param name="txtPassword"></param>
                    /// <returns></returns>
            public static string IsLogin(string txtUserName, string txtPassword)
            {
                string str = null;
                using (SqlConnection sc = new SqlConnection(CONN.ToString ()))
                {
                    using (SqlCommand scmd = new SqlCommand(" Select UserID,UserName,PasswordCode,IsUse From Users Where IsUse = 1 ", sc))
                    {
                        //打开数据管道
                        sc.Open();
                        using (SqlDataReader sdr = scmd.ExecuteReader())
                        {
                            while (sdr.Read())
                            {
                                //判断用户名是否正确正确的话！判断密码！否则的话返回一个字符串NAMEERROR
                                if (txtUserName == sdr["UserName"].ToString())
                                {
                                    //如果用户名正确则判断密码是否正确 正确的话返回OK 否则返回PASSWORDERROR
                                    if (txtPassword == sdr["PasswordCode"].ToString())
                                    {
                                        str = "OK";
                                    }
                                    else
                                    {
                                        str = "PASSWORDERROR";
                                    }
                                }
                                else
                                {
                                    str = "NAMEERROR";
                                }
                            }
                        }
                    }
                }
                return str;
            }
        }
        

    }
}
